package com.bases {
	import com.Interface.IBase;
	import com.skin.SkinManage;
	import com.utils.SCUiTool;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import flash.geom.Rectangle;
	import flash.text.TextField;
	import org.bytearray.display.ScaleBitmap;

	/**
	 * 按扭
	 * @author Administrator
	 */
	public class TButton extends TUIComponent implements IBase {
		private var _button:SimpleButton;
		private var _label:String;

		public function TButton(){
			_button = new SimpleButton();
			this.addChild(_button);
		}

		public function set enabled(value:Boolean):void {
			if (value){
				this.filters = null;
			} else {
				this.filters = [SCUiTool.buildGrayFilter()];
			}
			//super.enabled=value;
			super.mouseChildren = value;
			super.mouseEnabled = value;
		}

		/**
		 * 设置是否可以用tabEnabled
		 * @param enabled
		 *
		 */
		override public function set tabEnabled(enabled:Boolean):void {
			this.tabChildren = enabled;
			super.tabEnabled = enabled;
		}

		public function get enabled():Boolean {
			return this.mouseEnabled;
		}

		public function set label(value:String):void {
			_label = value;
			this.addSkin();
		}

		public function get label():String {
			return this._label;
		}

		private function buildState(label:String, stateStr:String = 'up'):Sprite {
			var state:Sprite = new Sprite();
			var label_tf:TextField = SCUiTool.buildButtonLabelTextField(stateStr);
			label_tf.text = label;
			var bmp:ScaleBitmap;
			switch (stateStr){
				case 'up':
					bmp = new ScaleBitmap(SkinManage.getInstance().getBitmapData('ButtonUp'));
					break;
				case 'over':
					bmp = new ScaleBitmap(SkinManage.getInstance().getBitmapData('ButtonOver'));
					break;
				case 'down':
					bmp = new ScaleBitmap(SkinManage.getInstance().getBitmapData('ButtonUp'));
					break;
				default:
					bmp = new ScaleBitmap(SkinManage.getInstance().getBitmapData('ButtonUp'));
					break;
			}
			/*bmp.scale9Grid=new Rectangle(13,6,28,12);
			 bmp.setSize(label_tf.textWidth+20,23);*/
			state.addChild(bmp);
			label_tf.x = bmp.width / 2 - label_tf.width / 2;
			label_tf.y = bmp.height / 2 - label_tf.height / 2;
			state.addChild(label_tf);
			state.mouseChildren = state.mouseEnabled = false;
			return state;
		}

		private function addSkin():void {
			this._button.upState = buildState(_label, 'up');
		/*this._button.downState=buildState(_label,'down');
		   this._button.overState=buildState(_label,'over');
		 this._button.hitTestState=this._button.upState;*/
		}
	}
}